#!/usr/bin/env bash
###
# 加载gz格式的离线Docker镜像包,推送到Local Registry
###
# set -x
set -eo pipefail

if [ -z "$1" ]; then
    echo "Usage: $0 image_package"
    exit 1
else
    pkg=$1
fi

if [ ! -f $pkg ]; then
    echo "$pkg not exists."
    exit 1
fi


registry_url={{registry_url}}

image_names=$(docker load -i $pkg | grep 'Loaded image' | awk -F':' '{print $2":"$3}' | awk '$1=$1')
image_name_arr=(${image_names// /})
for image_name in "${image_name_arr[@]}"
do
    echo "image name: $image_name"
    image_name_with_registry="$registry_url/$image_name"
    docker tag $image_name $image_name_with_registry
    docker push $image_name_with_registry
done
